﻿
// ReSharper disable CheckNamespace

using System.ComponentModel;

namespace System
{
    public static partial class NiuXStringExtensions
    {


        public static short ToInt16(this string str) => Convert.ToInt16(str);


        public static short ToShort(this string str) => Convert.ToInt16(str);


        public static int ToInt32(this string str) => Convert.ToInt32(str);


        public static int ToInt(this string str) => Convert.ToInt32(str);

        /// <returns></returns>
        public static long ToInt64(this string str) => Convert.ToInt64(str);

        public static long ToLong(this string str) => Convert.ToInt64(str);

        public static DateTime ToDateTime(this string str) => Convert.ToDateTime(str);

        public static bool ToBoolean(this string str) => Convert.ToBoolean(str);

        public static bool ToBool(this string str) => Convert.ToBoolean(str);


        public static T To<T>(this string input)
        {
            try
            {
                return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(input);
            }
            catch (Exception)
            {
                return default(T);
            }
        }

        public static object To(this string input, Type type)
        {
            try
            {
                return TypeDescriptor.GetConverter(type).ConvertFromString(input);
            }
            catch (Exception)
            {
                return null;
            }
        }

    }
}